package com.pathCompressionWeightQuickUnion;

import com.UF;
import com.weightedQuickUnion.WeightedQuickUnion;

/**
 * @author 罗俊华
 * @date 2021/5/10 - 10:27 上午
 * 路径压缩加权 quickUnion算法
 */
public class PathCompressionWeightQuickUnion extends WeightedQuickUnion {

    public PathCompressionWeightQuickUnion(int count) {
        super(count);
    }

    /**
     * 检查节点的同时将他们直接链接到根节点
     * 这样得到的记过就几乎是一棵扁平化的树
     * @param p
     * @return
     */
    @Override
    public int find(int p) {
        int originalContactPoint = p;
        p = super.find(p);
        this.id[originalContactPoint] = p;

        return p;
    }

}
